#pragma once
#include "OgreFrameListener.h"
#include "State.h"
#include "util.h"

class TimeListener{
public :
	Ogre::Real t;
	virtual void timeUp()=0;
};

#define  _MAX_TIME_LISTENER_NUM  10
class TimeMgr:public State,public Ogre::FrameListener
{
public:
	
	~TimeMgr(void){}
	void addListener(TimeListener* lis,Ogre::Real time){
		_listener[_lisNum++]=lis;
		lis->t=time;
	}
	void removeListener(TimeListener *tar){
		LOG("remove called");
		int i=0;
		for(;i<_lisNum;i++){
			if(tar==_listener[i]){
				break;
			}
		}
		for(;i+1<_lisNum;i++){
			_listener[i]=_listener[i+1];
		}
		--_lisNum;
	}

	void stateStarted();
	void stateEnded();
	bool frameRenderingQueued(const  Ogre::FrameEvent& evt);
	void init(){}
	static TimeMgr *getInstance(){
		static TimeMgr * instance=0;
		if(!instance){
			instance=new TimeMgr();
		}
		return instance;
	}
private:
	TimeMgr(void):_lisNum(0){}
	int _lisNum;
	TimeListener * _listener[_MAX_TIME_LISTENER_NUM];
};

